#include <iostream>
#include <string>

using std::cout;
using std::endl;
using std::string;

string get_method(string& buf) {
  auto pos = buf.find_first_of(' ');
  string method = buf.substr(0, pos);
  buf = buf.substr(pos + 1);
  return method;
}

string get_url(string& buf) {
  auto pos = buf.find_first_of(' ');
  return buf.substr(0, pos);
}

string get_file_type(string url) {
  auto pos = url.find_last_of('.');
  if (pos == -1) return "null";
  string file_type = url.substr(pos + 1);
  if (file_type == "html")
    return "text/html;charset=utf-8";
  else if (file_type == "txt")
    return "text/plain;charset=utf-8";
  else if (file_type == "js")
    return "text/js;charset=utf-8";
  else if (file_type == "css")
    return "text/css;charset=utf-8";
  else if (file_type == "jpeg")
    return "image/jpeg";
  else if (file_type == "ico")
    return "image/x-icon";
  else
    return "null";
}

